/**
 * @file dvc_manifold.h
 * @author yssickjgd (yssickjgd@mail.ustc.edu.cn)
 * @brief 妙算视觉
 * @version 0.1
 * @date 2022-08-13
 *
 * @copyright USTC-RoboWalker (c) 2022
 *
 */

#ifndef DVC_MANIFOLD_H
#define DVC_MANIFOLD_H

/* Includes ------------------------------------------------------------------*/

#include "drv_uart.h"

/* Exported macros -----------------------------------------------------------*/

//圆周率PI
#define PI (3.14159265f)

/* Exported types ------------------------------------------------------------*/

/**
 * @brief 妙算状态
 *
 */
enum Enum_Manifold_Status
{
    Manifold_Status_DISABLE = 0,
    Manifold_Status_ENABLE,
};

/**
 * @brief 妙算源数据
 * 
 */
struct Struct_Manifold_UART_Data
{
    uint16_t Frame_Header;
    int16_t Delta_Yaw;
    int16_t Delta_Pitch;
    int16_t Predicted_Delta_Yaw;
    int16_t Predicted_Delta_Pitch;
    int16_t Distance;
    int16_t Predicted_Velocity_Yaw;
    int16_t Predicted_Velocity_Pitch;
    uint16_t Data_Flag;
};

/**
 * @brief 串口接收的视觉数据
 * 
 */
struct Struct_Manifold_Data
{
    uint16_t Data_Flag;
    float Delta_Yaw;
    float Delta_Pitch;
    float Predicted_Delta_Yaw;
    float Predicted_Delta_Pitch;
    float Predicted_Velocity_Yaw;
    float Predicted_Velocity_Pitch;
    float Distance;
};

class Class_Manifold
{
public:
    void Init(UART_HandleTypeDef *__huart, uint16_t __Frame_Header = 0xABCD);

    uint16_t Get_Data_Flag();
    float Get_Delta_Yaw();
    float Get_Delta_Pitch();
    float Get_Predicted_Delta_Yaw();
    float Get_Predicted_Delta_Pitch();
    float Get_Predicted_Velocity_Yaw();
    float Get_Predicted_Velocity_Pitch();
    float Get_Distance();
    
    void TIM_Alive_PeriodElapsedCallback();
    void UART_RxCpltCallback(uint8_t *Rx_Data);

protected:
    //初始化相关常量

    //绑定的UART编号
    UART_HandleTypeDef *huart;
    //发送缓冲区
    uint8_t *UART_Tx_Data;
    //接收缓冲区
    Struct_Manifold_UART_Data *UART_Rx_Data;
    //数据包头标
    uint16_t Frame_Header;

    //常量

    //内部变量

    //当前时刻的妙算接收flag
    uint32_t Flag;
    //前一时刻的妙算接收flag
    uint32_t Pre_Flag;

    //读变量

    //视觉状态
    Enum_Manifold_Status Manifold_Status = Manifold_Status_DISABLE;
    //视觉对外接口信息
    Struct_Manifold_Data Data;

    //写变量

    //读写变量

    //内部函数

    void Reset_UART_Rx_Data();
    void Data_Process();
};

/* Exported variables --------------------------------------------------------*/

/* Exported function declarations --------------------------------------------*/

#endif

/************************ COPYRIGHT(C) USTC-ROBOWALKER **************************/
